package com.jmb.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmb.api.common.exception.LeaseException;
import com.jmb.api.common.result.ResultCodeEnum;
import com.jmb.api.mapper.ApiTestCaseMapper;
import com.jmb.api.model.entity.ApiTestCase;
import com.jmb.api.service.ApiTestCaseService;
import com.jmb.api.service.ApiTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApiTestServiceImpl extends ServiceImpl<ApiTestCaseMapper, ApiTestCase>
        implements ApiTestService {
    @Autowired
    private ApiTestCaseMapper apiTestCaseMapper;
    @Override
    public ApiTestCase getApiTestCaseById(Integer id) {
        // 查询数据是否存在
            if (id == null){
                throw new LeaseException(ResultCodeEnum.WEB_API_ID_NOT_NULL);
            }
            return apiTestCaseMapper.selectById(id);
        }

    @Override
    public Long getApiTestCount(Integer apiTestCaseId) {
        if (apiTestCaseId == null){
            throw new LeaseException(ResultCodeEnum.WEB_API_ID_NOT_NULL);
        }
        LambdaQueryWrapper<ApiTestCase> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApiTestCase::getCaseId, apiTestCaseId);
        return apiTestCaseMapper.selectCount(queryWrapper);
    }

    @Override
    public void selectByCaseId(Integer caseId) {
        // 查询caseId是否存在，如果不存在则提示caseId不存在
        if (getApiTestCaseById(caseId)==null){
            throw new LeaseException(ResultCodeEnum.WEB_API_CASEID_NOT);
        }

    }

}
